import { isEmpty } from 'shiptools'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    /**
     * 元素的颜色
     */
    color: {
      type: String,
      value: ''
    },
    /**
     * 元素的状态
     */
    status: {
      type: String,
      value: 'progress' | 'error' | 'success'
    },
    /**
     * 元素的进度
     */
    percent: {
      type: Number,
      value: 0,
      observer: function (newVal, oldVal) { 
        if(newVal !== oldVal) {
          this.setPercent(newVal)
        }
      }
    },
    /**
     * 元素的规格
     */
    strokeWidth: {
      type: Number,
      value: 0
    },
    /**
     * 是否隐藏文字
     */
    isHidePercent: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    progressStyle: {}
  },
  ready: function() {
    
  },
  /**
   * 组件的方法列表
   */
  methods: {
    setPercent: function(percent) {
      const {color, strokeWidth} = this.data
      if (typeof percent !== 'number') {
        percent = 0
      }

      if (percent < 0) {
        percent = 0
      } else if (percent > 100) {
        percent = 100
      }

      const progressStyle = `width:${+percent}%;height:${+strokeWidth}px;background-color: ${color};`
      this.setData({
        progressStyle,
        percent
      })
    }
  },

  
  lifetimes: {
    
    attached: function() {
      const that = this
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  
    error: function() {
      this.setData({
        errorState: true
      })
    }
  }
})
